import getRoutes from "./router";
import env from "./env";
export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: "艺览天下之海淀",
    htmlAttrs: {
      lang: "en",
    },
    meta: [
      { charset: "utf-8" },
      {
        name: "viewport",
        content:
          "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no",
      },
      { hid: "description", name: "description", content: "Nuxt.js project" },
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
    script: [
      {
        src: "/rem.js",
        type: "text/javascript",
        charset: "utf-8", //移动端适配
      },
    ],
  },

  server: {
    host: "0.0.0.0",
    port: 3000,
  },

  router: {
    extendRoutes: (routes, resolve) => {
      // 清空Nuxt.js自动生成的路由
      routes.splice(0);
      // 重新将自定义路由配置设置进去
      routes.push(...getRoutes);
    },
  },
  // extractCSS: process.env.NODE_ENV === 'production',
  env: {
    NODE_ENV: env[process.env.NODE_ENV].NODE_ENV,
    API_URL: env[process.env.NODE_ENV].API_URL,
    NUXT_API_URL: env[process.env.NODE_ENV].NUXT_API_URL,
  },
  axios: {
    proxy: true,
    prefix: "/",
  },

  proxy: {
    "/webapi/1008": {
      target: "http://122.226.166.67:18080",
      changeOrigin: true,
      ws: true,
      pathRewrite: {
        "^/webapi/1008": "/",
      },
    },
    "/webapi/2008": {
      target: "http://122.226.166.67:28080",
      changeOrigin: true,
      ws: true,
      pathRewrite: {
        "^/webapi/2008": "/",
      },
    },
    "/webapi/8088": {
      target: "http://122.226.166.67:8088",
      changeOrigin: true,
      ws: true,
      pathRewrite: {
        "^/webapi/8088": "/",
      },
    },
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: ["element-ui/lib/theme-chalk/index.css", "assets/main.less"],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    "@/plugins/element-ui",
    "@/plugins/DynamicApi.js",
    "@/plugins/navigation.js",
    { src: "@/plugins/vant.js", ssr: false },
    // "@/plugins/router",
    { src: "@/plugins/videoPlayer", ssr: false },
    { src: "@/plugins/localStorage", ssr: false },
    // { src: , ssr: false },
    // {src: '@/plugins/rem.js', ssr: false}
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    "@nuxtjs/axios",
    "nuxt-user-agent",
    "@nuxtjs/style-resources",
    "cookie-universal-nuxt",
    "@nuxtjs/proxy",
  ],
  styleResources: {
    sass: [],
    scss: [],
    less: [],
    stylus: [],
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: [/^element-ui/],
    postcss: {
      plugins: {
        "postcss-px-to-viewport": {
          unitToConvert: "px", // 要转化的单位
          viewportWidth: 1920, // UI设计稿的宽度
          unitPrecision: 6, // 转换后的精度，即小数点位数
          propList: ["*"], // 指定转换的css属性的单位，*代表全部css属性的单位都进行转换
          viewportUnit: "vw", // 指定需要转换成的视窗单位，默认vw
          fontViewportUnit: "vw", // 指定字体需要转换成的视窗单位，默认vw
          selectorBlackList: ["wrap"], // 指定不转换为视窗单位的类名，
          minPixelValue: 1, // 默认值1，小于或等于1px则不进行转换
          mediaQuery: false, // 是否在媒体查询的css代码中也进行转换，默认false
          replace: true, // 是否转换后直接更换属性值
          exclude: [/node_modules/], // 设置忽略文件，用正则做目录名匹配
          landscape: false, // 是否处理横屏情况
          landscapeUnit: "vw", // 横屏时使用的单位
          // landscapeWidth: 1920
        },
        "postcss-functions": {
          functions: {
            pxtorem: function (value) {
              return value / 75 + "rem";
            },
          },
        },
      },
    },
    extend(config, ctx) {
      const sassResourcesLoader = {
        loader: "sass-resources-loader",
        options: {
          resources: ["assets/style/theme.less", "assets/style/mixins.less"],
        },
      };
      config.module.rules.forEach((rule) => {
        if (rule.test.toString() === "/\\.vue$/") {
          rule.options.loaders.less.push(sassResourcesLoader);
        }
        if (rule.test.toString() === "/\\.less$/") {
          rule.use.push(sassResourcesLoader);
        }
      });
    },
    babel: { compact: true },
  },
};
